Total Complexity | 2 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
17 | |||
18 | @Controller('schools') |
||
19 | @ApiTags('School') |
||
20 | @ApiBearerAuth() |
||
21 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
22 | export class CreateSchoolAction { |
||
23 | constructor( |
||
24 | @Inject('ICommandBus') |
||
25 | private readonly commandBus: ICommandBus |
||
26 | ) {} |
||
27 | |||
28 | @Post() |
||
29 | @Roles(UserRole.PHOTOGRAPHER) |
||
30 | @ApiOperation({ summary: 'Create new school' }) |
||
31 | public async index(@Body() dto: SchoolDTO) { |
||
32 | const { |
||
33 | reference, |
||
34 | name, |
||
35 | address, |
||
36 | zipCode, |
||
37 | city, |
||
38 | email, |
||
39 | phoneNumber, |
||
40 | numberOfClasses, |
||
41 | numberOfStudents, |
||
42 | observation, |
||
43 | status, |
||
44 | type |
||
45 | } = dto; |
||
46 | |||
47 | try { |
||
48 | const id = await this.commandBus.execute( |
||
49 | new CreateSchoolCommand( |
||
50 | reference, |
||
51 | name, |
||
52 | address, |
||
53 | zipCode, |
||
54 | city, |
||
55 | status, |
||
56 | type, |
||
57 | email, |
||
58 | phoneNumber, |
||
59 | numberOfStudents, |
||
60 | numberOfClasses, |
||
61 | observation |
||
62 | ) |
||
63 | ); |
||
64 | |||
65 | return { id }; |
||
66 | } catch (e) { |
||
67 | throw new BadRequestException(e.message); |
||
68 | } |
||
71 |